package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.Mappers.NaExamMapper;
import com.example.demo.Mappers.RegistMapper;
import com.example.demo.beans.*;
import com.example.demo.utils.AppConfigUtils;
import com.example.demo.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.jackson.JsonObjectSerializer;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**核酸检测Controller
 * Created by 黄启位 on 2022-01-18.
 */
@RestController
public class NaExamController {
    @Autowired
    private NaExamMapper mapper;
    @Autowired
    private RegistMapper rmapper;

/***获取核酸检测数据***/
    @ResponseBody
    @RequestMapping(value = "GetNaExamItemInfo",produces = {"application/xml"})
    public NaExamItemResponse GetNaexamInfo(){
        NaExamItemResponse response=new NaExamItemResponse();
        List<NaExamItemBean>beans=new ArrayList<>();
        beans=mapper.GetNaExamItem();
        response.setResultCode("0");
        response.setResultMsg("请求成功！");
        response.setItems(beans);
        return response;
    }

    /*****
     * 执行核酸检测缴费
     * @param r
     * @return
     */
    @ResponseBody
@RequestMapping(value = "ExeNaExam",produces = {"application/xml"},method = RequestMethod.POST)
  @Transactional(readOnly = true)
    public NaExamResponse NaExam(@RequestBody NaExamRequest r){

        NaExamResponse response=new NaExamResponse();
        String sqysbm="0196";
        String sqksbm="0084";
        String sqysxm="周俊";
        String TypeName="免费挂号";
        String TypeID="04";
        String sqksmc="核酸实验室";
        String czybm= AppConfigUtils.getGhybm();
        String czyxm=AppConfigUtils.getCzyxm();
        String czyks=AppConfigUtils.getGhyks();
        String ywckbm=AppConfigUtils.getYwckbm();
        String ghfsbm=AppConfigUtils.getGhfsbm();
        String fbbm=AppConfigUtils.getFbbm();
        System.out.print("核酸检测请求:"+JSON.toJSONString(r));
        //登记日期，一般为当日
        String ghrq= DateUtils.Getdnowdatexx();
        Ghxh_YwckBean ghxh_ywckBean=rmapper.getGhxhYwxh();
        String tempghxh=ghxh_ywckBean.getXh();
        String ghxh="";
        String ghzlbm="04";
        Long tempyyghid=Long.parseLong(DateUtils.getStringToday()+"000000");
       //系统里面的日期和现在挂号时间所相差的天数
        int m=DateUtils.daysBetween(ghxh_ywckBean.getSsrq());
        Jysqh_YwckBean jysqh_ywckBean=rmapper.getJysqxhYwxh();
        String tempjysqxh=jysqh_ywckBean.getXh();
        String jysqxh="";
        String lczd="核酸检测(线上支付)";
        //检验申请中数据库中日期与当前日期相差的天数
        int k=DateUtils.daysBetween(jysqh_ywckBean.getSsrq());

        Jsjl_YwxhBean jsjl_ywxhBean=rmapper.getJsjlywxh();
        String tempjsxh=jsjl_ywxhBean.getXh();
        String jsjlid="";
        //结算记录时间与上次结算时间相差的天数
        int i=DateUtils.daysBetween(jsjl_ywxhBean.getSsrq());

        NaExamPatientInfo info=new NaExamPatientInfo();
        //当请求的人员ID不为空时候
        if(r.getPatientId()!=null){
            info=mapper.GetNaExamPatintInfo(r.getPatientId());
          //当获取到该人员的信息不为空时候执行
            if(info!=null){
                NaExamItemBean bean=mapper.GetNaExamItemBybm(r.getXmbm());
             //当通过明细费用项目编码获取到的项目信息不为空时候执行
              if(bean!=null)
              {//当支付金额与应支付金额相等时候
                  if(Double.valueOf(r.getPayAmt())-Double.valueOf(bean.getFydj())==0){

                      //门诊发票信息
                      MzdqpjBean mzdqpjBean=rmapper.Getmzpjxx(czybm);
                      String qshnew=String.valueOf(Long.valueOf(mzdqpjBean.getQsh())+1);
                      rmapper.updatemzdqqj(qshnew,mzdqpjBean.getQsh(),mzdqpjBean.getJsh(),mzdqpjBean.getFpjlid(),czybm);
                      //当是当日首次挂核酸时候执行
                      //m表示挂号天数与数库时间之间的差，k表示检验申请时间与数据库时间的差，i表示结算时间与数据库时间的差
                      if(m>=1&&k>=1&&i>=1){
                          ghxh=ifmthanone(tempyyghid,ghzlbm,ghfsbm,fbbm,r.getPatientId(),czybm,czyks,
                                  info.getAge(),ghrq,ywckbm,sqksbm,sqysbm);
                          jysqxh=jysqthan(tempyyghid,ywckbm,ghxh,bean.getHsks(),"0",lczd,sqysbm,DateUtils.Getdnowdatexx(),bean.getFydj(),
                         "0",bean.getFydj(),DateUtils.Getdnowdatexx(),sqysbm,sqksbm,sqysbm,DateUtils.Getdnowdatexx(),"2",bean.getXmbm(),bean.getFydj(),czybm,DateUtils.Getdnowdatexx());
                          jsjlid=jsjlThan(tempyyghid,ghxh,czybm,ywckbm,info.getPatientId(),bean.getFydj(),czyks,info.getCardNo());
                          AutoOrderBean a=setAutoBean(TypeName,TypeID,sqksmc,sqksbm,sqysbm,ghrq,ghxh,"","0","1",r.getPatientId(),info.getCardNo(),sqysxm,czybm,czyxm);
                          rmapper.saveyyjl(a);
                          mzbBrfyBean mBrfyBean=new mzbBrfyBean();
                          mBrfyBean=setFyBean(fbbm,ywckbm,bean.getXlbm(),bean.getXmbm(),czybm,bean.getDlbm(),DateUtils.Getdnowdatexx(),info.getPatientId(),ghxh,info.getName(),"1","0",bean.getFydj(),bean.getFydj(),sqysbm,
                                sqksbm,bean.getHsks(),bean.getHsks(),"4",jysqxh,"1","线上核酸检测申请","1",lczd,"0","0","1",czybm,DateUtils.Getdnowdatexx(),qshnew,jsjlid);
                          mapper.InsertMzfyb(mBrfyBean);
                          PayDetailBean pay=new PayDetailBean();
                          pay=setPayBean(info,jsjlid,r,czybm,czyxm);
                          mapper.InsertAutoRegist(pay);
                      List<NaExamReBean> beans=new ArrayList<>();
                      beans=mapper.GetNaExamRes(r.getPatientId());
                      response.setResultCode("0");
                      response.setItem(beans);
                      response.setResultMsg("请求成功！");
                      return response;
                      }
                      //m表示挂号天数与数库时间之间的差，k表示检验申请时间与数据库时间的差，i表示结算时间与数据库时间的差
                      if(m>=1&&k>=1&&i<1){
                          ghxh=ifmthanone(tempyyghid,ghzlbm,ghfsbm,fbbm,r.getPatientId(),czybm,czyks,
                                  info.getAge(),ghrq,ywckbm,sqksbm,sqysbm);
                          jysqxh=jysqthan(tempyyghid,ywckbm,ghxh,bean.getHsks(),"0",lczd,sqysbm,DateUtils.Getdnowdatexx(),bean.getFydj(),
                                  "0",bean.getFydj(),DateUtils.Getdnowdatexx(),sqysbm,sqksbm,sqysbm,DateUtils.Getdnowdatexx(),"2",bean.getXmbm(),bean.getFydj(),czybm,DateUtils.Getdnowdatexx());
                          jsjlid=jsjlLess(tempyyghid,tempjsxh,ghxh,czybm,ywckbm,info.getPatientId(),bean.getFydj(),czyks,info.getCardNo());
                          AutoOrderBean a=setAutoBean(TypeName,TypeID,sqksmc,sqksbm,sqysbm,ghrq,ghxh,"","0","1",r.getPatientId(),info.getCardNo(),sqysxm,czybm,czyxm);
                          rmapper.saveyyjl(a);
                          mzbBrfyBean mBrfyBean=new mzbBrfyBean();
                          mBrfyBean=setFyBean(fbbm,ywckbm,bean.getXlbm(),bean.getXmbm(),czybm,bean.getDlbm(),DateUtils.Getdnowdatexx(),info.getPatientId(),ghxh,info.getName(),"1","0",bean.getFydj(),bean.getFydj(),sqysbm,
                                  sqksbm,bean.getHsks(),bean.getHsks(),"4",jysqxh,"1","线上核酸检测申请","1",lczd,"0","0","1",czybm,DateUtils.Getdnowdatexx(),qshnew,jsjlid);
                          mapper.InsertMzfyb(mBrfyBean);
                          PayDetailBean pay=new PayDetailBean();
                          pay=setPayBean(info,jsjlid,r,czybm,czyxm);
                          mapper.InsertAutoRegist(pay);
                          List<NaExamReBean> beans=new ArrayList<>();
                          beans=mapper.GetNaExamRes(r.getPatientId());
                          response.setResultCode("0");
                          response.setResultMsg("请求成功！");
                          response.setItem(beans);
                          return response;
                      }
                      if(m>=1&&k<1&&i>=1){
                          ghxh=ifmthanone(tempyyghid,ghzlbm,ghfsbm,fbbm,r.getPatientId(),czybm,czyks,
                                  info.getAge(),ghrq,ywckbm,sqksbm,sqysbm);
                          jysqxh=jysqLess(tempyyghid,ywckbm,ghxh,bean.getHsks(),"0",lczd,sqysbm,DateUtils.Getdnowdatexx(),bean.getFydj(),
                                  "0",bean.getFydj(),DateUtils.Getdnowdatexx(),sqysbm,sqksbm,sqysbm,DateUtils.Getdnowdatexx(),"2",bean.getXmbm(),bean.getFydj(),tempjysqxh,czybm,DateUtils.Getdnowdatexx());
                          jsjlid=jsjlThan(tempyyghid,ghxh,czybm,ywckbm,info.getPatientId(),bean.getFydj(),czyks,info.getCardNo());
                          AutoOrderBean a=setAutoBean(TypeName,TypeID,sqksmc,sqksbm,sqysbm,ghrq,ghxh,"","0","1",r.getPatientId(),info.getCardNo(),sqysxm,czybm,czyxm);
                          rmapper.saveyyjl(a);
                          mzbBrfyBean mBrfyBean=new mzbBrfyBean();
                          mBrfyBean=setFyBean(fbbm,ywckbm,bean.getXlbm(),bean.getXmbm(),czybm,bean.getDlbm(),DateUtils.Getdnowdatexx(),info.getPatientId(),ghxh,info.getName(),"1","0",bean.getFydj(),bean.getFydj(),sqysbm,
                                  sqksbm,bean.getHsks(),bean.getHsks(),"4",jysqxh,"1","线上核酸检测申请","1",lczd,"0","0","1",czybm,DateUtils.Getdnowdatexx(),qshnew,jsjlid);
                          mapper.InsertMzfyb(mBrfyBean);
                          PayDetailBean pay=new PayDetailBean();
                          pay=setPayBean(info,jsjlid,r,czybm,czyxm);
                          mapper.InsertAutoRegist(pay);
                          List<NaExamReBean> beans=new ArrayList<>();
                          beans=mapper.GetNaExamRes(r.getPatientId());
                          response.setResultCode("0");
                          response.setResultMsg("请求成功！");
                          response.setItem(beans);
                          return response;
                      }

                      if(m>=1&&k<1&&i<1){
                          ghxh=ifmthanone(tempyyghid,ghzlbm,ghfsbm,fbbm,r.getPatientId(),czybm,czyks,
                                  info.getAge(),ghrq,ywckbm,sqksbm,sqysbm);
                          jysqxh=jysqLess(tempyyghid,ywckbm,ghxh,bean.getHsks(),"0",lczd,sqysbm,DateUtils.Getdnowdatexx(),bean.getFydj(),
                                  "0",bean.getFydj(),DateUtils.Getdnowdatexx(),sqysbm,sqksbm,sqysbm,DateUtils.Getdnowdatexx(),"2",bean.getXmbm(),bean.getFydj(),tempjysqxh,czybm,DateUtils.Getdnowdatexx());
                          jsjlid=jsjlLess(tempyyghid,tempjsxh,ghxh,czybm,ywckbm,info.getPatientId(),bean.getFydj(),czyks,info.getCardNo());
                          AutoOrderBean a=setAutoBean(TypeName,TypeID,sqksmc,sqksbm,sqysbm,ghrq,ghxh,"","0","1",r.getPatientId(),info.getCardNo(),sqysxm,czybm,czyxm);
                          rmapper.saveyyjl(a);
                          mzbBrfyBean mBrfyBean=new mzbBrfyBean();
                          mBrfyBean=setFyBean(fbbm,ywckbm,bean.getXlbm(),bean.getXmbm(),czybm,bean.getDlbm(),DateUtils.Getdnowdatexx(),info.getPatientId(),ghxh,info.getName(),"1","0",bean.getFydj(),bean.getFydj(),sqysbm,
                                  sqksbm,bean.getHsks(),bean.getHsks(),"4",jysqxh,"1","线上核酸检测申请","1",lczd,"0","0","1",czybm,DateUtils.Getdnowdatexx(),qshnew,jsjlid);
                          mapper.InsertMzfyb(mBrfyBean);
                          PayDetailBean pay=new PayDetailBean();
                          pay=setPayBean(info,jsjlid,r,czybm,czyxm);
                          mapper.InsertAutoRegist(pay);
                          List<NaExamReBean> beans=new ArrayList<>();
                          beans=mapper.GetNaExamRes(r.getPatientId());
                          response.setResultCode("0");
                          response.setResultMsg("请求成功！");
                          response.setItem(beans);
                          return response;
                      }
                      //m表示挂号天数与数库时间之间的差，k表示检验申请时间与数据库时间的差，i表示结算时间与数据库时间的差
                      if(m<1&&k>=1&&i>=1){
                          ghxh=ifmlessone(tempyyghid,ghzlbm,ghfsbm,fbbm,r.getPatientId(),czybm,czyks,
                                  info.getAge(),ghrq,ywckbm,tempghxh,sqksbm,sqysbm);
                          jysqxh=jysqthan(tempyyghid,ywckbm,ghxh,bean.getHsks(),"0",lczd,sqysbm,DateUtils.Getdnowdatexx(),bean.getFydj(),
                                  "0",bean.getFydj(),DateUtils.Getdnowdatexx(),sqysbm,sqksbm,sqysbm,DateUtils.Getdnowdatexx(),"2",bean.getXmbm(),bean.getFydj(),czybm,DateUtils.Getdnowdatexx());
                          jsjlid=jsjlThan(tempyyghid,ghxh,czybm,ywckbm,info.getPatientId(),bean.getFydj(),czyks,info.getCardNo());
                          AutoOrderBean a=setAutoBean(TypeName,TypeID,sqksmc,sqksbm,sqysbm,ghrq,ghxh,"","0","1",r.getPatientId(),info.getCardNo(),sqysxm,czybm,czyxm);
                          rmapper.saveyyjl(a);
                          mzbBrfyBean mBrfyBean=new mzbBrfyBean();
                          mBrfyBean=setFyBean(fbbm,ywckbm,bean.getXlbm(),bean.getXmbm(),czybm,bean.getDlbm(),DateUtils.Getdnowdatexx(),info.getPatientId(),ghxh,info.getName(),"1","0",bean.getFydj(),bean.getFydj(),sqysbm,
                                  sqksbm,bean.getHsks(),bean.getHsks(),"4",jysqxh,"1","线上核酸检测申请","1",lczd,"0","0","1",czybm,DateUtils.Getdnowdatexx(),qshnew,jsjlid);
                          mapper.InsertMzfyb(mBrfyBean);
                          PayDetailBean pay=new PayDetailBean();
                          pay=setPayBean(info,jsjlid,r,czybm,czyxm);
                          mapper.InsertAutoRegist(pay);
                          List<NaExamReBean> beans=new ArrayList<>();
                          beans=mapper.GetNaExamRes(r.getPatientId());
                          response.setResultCode("0");
                          response.setResultMsg("请求成功！");
                          response.setItem(beans);
                          return response;
                      }
                      //m表示挂号天数与数库时间之间的差，k表示检验申请时间与数据库时间的差，i表示结算时间与数据库时间的差
                      if(m<1&&k>=1&&i<1){
                          ghxh=ifmlessone(tempyyghid,ghzlbm,ghfsbm,fbbm,r.getPatientId(),czybm,czyks,
                                  info.getAge(),ghrq,ywckbm,tempghxh,sqksbm,sqysbm);
                          jysqxh=jysqthan(tempyyghid,ywckbm,ghxh,bean.getHsks(),"0",lczd,sqysbm,DateUtils.Getdnowdatexx(),bean.getFydj(),
                                  "0",bean.getFydj(),DateUtils.Getdnowdatexx(),sqysbm,sqksbm,sqysbm,DateUtils.Getdnowdatexx(),"2",bean.getXmbm(),bean.getFydj(),czybm,DateUtils.Getdnowdatexx());
                          jsjlid=jsjlLess(tempyyghid,tempjsxh,ghxh,czybm,ywckbm,info.getPatientId(),bean.getFydj(),czyks,info.getCardNo());
                          AutoOrderBean a=setAutoBean(TypeName,TypeID,sqksmc,sqksbm,sqysbm,ghrq,ghxh,"","0","1",r.getPatientId(),info.getCardNo(),sqysxm,czybm,czyxm);
                          rmapper.saveyyjl(a);
                          mzbBrfyBean mBrfyBean=new mzbBrfyBean();
                          mBrfyBean=setFyBean(fbbm,ywckbm,bean.getXlbm(),bean.getXmbm(),czybm,bean.getDlbm(),DateUtils.Getdnowdatexx(),info.getPatientId(),ghxh,info.getName(),"1","0",bean.getFydj(),bean.getFydj(),sqysbm,
                                  sqksbm,bean.getHsks(),bean.getHsks(),"4",jysqxh,"1","线上核酸检测申请","1",lczd,"0","0","1",czybm,DateUtils.Getdnowdatexx(),qshnew,jsjlid);
                          mapper.InsertMzfyb(mBrfyBean);
                          PayDetailBean pay=new PayDetailBean();
                          pay=setPayBean(info,jsjlid,r,czybm,czyxm);
                          mapper.InsertAutoRegist(pay);
                          List<NaExamReBean> beans=new ArrayList<>();
                          beans=mapper.GetNaExamRes(r.getPatientId());
                          response.setResultCode("0");
                          response.setResultMsg("请求成功！");
                          response.setItem(beans);
                          return response;
                      }
                      if(m<1&&k<1&&i>=1){
                          ghxh=ifmlessone(tempyyghid,ghzlbm,ghfsbm,fbbm,r.getPatientId(),czybm,czyks,
                                  info.getAge(),ghrq,ywckbm,tempghxh,sqksbm,sqysbm);
                          jysqxh=jysqLess(tempyyghid,ywckbm,ghxh,bean.getHsks(),"0",lczd,sqysbm,DateUtils.Getdnowdatexx(),bean.getFydj(),
                                  "0",bean.getFydj(),DateUtils.Getdnowdatexx(),sqysbm,sqksbm,sqysbm,DateUtils.Getdnowdatexx(),"2",bean.getXmbm(),bean.getFydj(),tempjysqxh,czybm,DateUtils.Getdnowdatexx());
                          jsjlid=jsjlThan(tempyyghid,ghxh,czybm,ywckbm,info.getPatientId(),bean.getFydj(),czyks,info.getCardNo());
                          AutoOrderBean a=setAutoBean(TypeName,TypeID,sqksmc,sqksbm,sqysbm,ghrq,ghxh,"","0","1",r.getPatientId(),info.getCardNo(),sqysxm,czybm,czyxm);
                          rmapper.saveyyjl(a);
                          mzbBrfyBean mBrfyBean=new mzbBrfyBean();
                          mBrfyBean=setFyBean(fbbm,ywckbm,bean.getXlbm(),bean.getXmbm(),czybm,bean.getDlbm(),DateUtils.Getdnowdatexx(),info.getPatientId(),ghxh,info.getName(),"1","0",bean.getFydj(),bean.getFydj(),sqysbm,
                                  sqksbm,bean.getHsks(),bean.getHsks(),"4",jysqxh,"1","线上核酸检测申请","1",lczd,"0","0","1",czybm,DateUtils.Getdnowdatexx(),qshnew,jsjlid);
                          mapper.InsertMzfyb(mBrfyBean);
                          PayDetailBean pay=new PayDetailBean();
                          pay=setPayBean(info,jsjlid,r,czybm,czyxm);
                          mapper.InsertAutoRegist(pay);
                          List<NaExamReBean> beans=new ArrayList<>();
                          beans=mapper.GetNaExamRes(r.getPatientId());
                          response.setResultCode("0");
                          response.setResultMsg("请求成功！");
                          response.setItem(beans);
                          return response;
                      }
                      if(m<1&&k<1&&i<1){
                          ghxh=ifmlessone(tempyyghid,ghzlbm,ghfsbm,fbbm,r.getPatientId(),czybm,czyks,
                                  info.getAge(),ghrq,ywckbm,tempghxh,sqksbm,sqysbm);
                          jysqxh=jysqLess(tempyyghid,ywckbm,ghxh,bean.getHsks(),"0",lczd,sqysbm,DateUtils.Getdnowdatexx(),bean.getFydj(),
                                  "0",bean.getFydj(),DateUtils.Getdnowdatexx(),sqysbm,sqksbm,sqysbm,DateUtils.Getdnowdatexx(),"2",bean.getXmbm(),bean.getFydj(),tempjysqxh,czybm,DateUtils.Getdnowdatexx());
                          jsjlid=jsjlLess(tempyyghid,tempjsxh,ghxh,czybm,ywckbm,info.getPatientId(),bean.getFydj(),czyks,info.getCardNo());
                          AutoOrderBean a=setAutoBean(TypeName,TypeID,sqksmc,sqksbm,sqysbm,ghrq,ghxh,"","0","1",r.getPatientId(),info.getCardNo(),sqysxm,czybm,czyxm);
                          rmapper.saveyyjl(a);
                          mzbBrfyBean mBrfyBean=new mzbBrfyBean();
                          mBrfyBean=setFyBean(fbbm,ywckbm,bean.getXlbm(),bean.getXmbm(),czybm,bean.getDlbm(),DateUtils.Getdnowdatexx(),info.getPatientId(),ghxh,info.getName(),"1","0",bean.getFydj(),bean.getFydj(),sqysbm,
                                  sqksbm,bean.getHsks(),bean.getHsks(),"4",jysqxh,"1","线上核酸检测申请","1",lczd,"0","0","1",czybm,DateUtils.Getdnowdatexx(),qshnew,jsjlid);
                          mapper.InsertMzfyb(mBrfyBean);
                          PayDetailBean pay=new PayDetailBean();
                          pay=setPayBean(info,jsjlid,r,czybm,czyxm);
                          mapper.InsertAutoRegist(pay);
                          List<NaExamReBean> beans=new ArrayList<>();
                          beans=mapper.GetNaExamRes(r.getPatientId());
                          response.setResultCode("0");
                          response.setResultMsg("请求成功！");
                          response.setItem(beans);
                          return response;
                      }

                  }
                //当支付金额与应支付金额不等的时候执行
                  else {
                      response.setResultCode("1");
                      response.setResultMsg("支付金额与应支付金额不等，实际应支付金额为人民币："+bean.getFydj()+"元");
                      return response;
                  }

              }
              //当通过项目编码获取项目信息为空时候执行
               else {
                  response.setResultCode("1");
                  response.setResultMsg("传入的项目编码错误，请联系管理员");
                  return response;}
            }
            //获取病人信息为空时候执行
            else {
                response.setResultCode("1");
                response.setResultMsg("根据请求参数未获取到病人信息，请检查请求数据是否错误！");
                return response;
            }
        }
        //病人ID未空时候执行
        else {
            response.setResultCode("1");
            response.setResultMsg("请求的PatiendId为空，请联系管理人员！");
            return response;
        }
        response .setResultCode("1");
        response.setResultMsg("请检查请求参数");
        return  response;
    }
    /**
     * 当挂号业务序号表大于1
     * @param tempghxh
     * @param ghzlbm
     * @param ghfsbm
     * @param fbbm
     * @param brid
     * @param czybm
     * @param czyks
     * @param brnl
     * @param zcrq
     * @param ywckbm
     */
    private  String ifmthanone(Long tempghxh,String ghzlbm,String ghfsbm,String fbbm,String brid,
                               String czybm,String czyks,String brnl,String zcrq,String ywckbm,String ghks,String jzys){
        rmapper.updateghxhywxh("000001",DateUtils.Getdnowdatexx());
        String  ghxh=String.valueOf(tempghxh+1);
        rmapper.saveghb(ghxh,ghzlbm,ghfsbm,fbbm,brid,czybm,czyks,
                ghks,brnl,zcrq,zcrq,ywckbm,jzys);
        rmapper.updatesfysghf(ghxh);
        return  ghxh;
    }

    /**
     * 获取线上核酸检测缴费结果信息
     * @param r
     * @return
     */
   @ResponseBody
   @RequestMapping(value = "GetNaExamInfo",produces = {"application/xml"})
   public  NaExamResponse GetNaExaminfo(@RequestBody GetNaExamReqest r){
       NaExamResponse response =new NaExamResponse();
       if(r!=null){
           if(r.getPatientId()!=null){
               List<NaExamReBean>beans=new ArrayList<>();
               beans=mapper.GetNaExamRes(r.getPatientId());
               if(beans==null||beans.isEmpty()){
                   response.setResultCode("1");
                   response.setResultMsg("查询成功，但未查到该人员相关信息！");
                   return response;
               }
               else {
                   response.setResultCode("0");
                   response.setResultMsg("查询成功！");
                   response.setItem(beans);
                   return response;
               }
           }
           else {
               response.setResultCode("1");
               response.setResultMsg("请求的patientId为空，请检查！");
               return response;
           }
       }
       else {
           response.setResultCode("1");
           response.setResultMsg("请求参数为空，请检查");
           return response;
       }

   }
    /**
     * 当挂号时间等于当天时间
     * @param tempghxh
     * @param ghzlbm
     * @param ghfsbm
     * @param fbbm
     * @param brid
     * @param czybm
     * @param czyks
     * @param brnl
     * @param zcrq
     * @param ywckbm
     * @param xh
     * @return
     */
    private  String ifmlessone(Long tempghxh,String ghzlbm,String ghfsbm,String fbbm,String brid,
                               String czybm,String czyks,String brnl,String zcrq,String ywckbm,String xh,String ghks,String jzys){
        int xh1 = Integer.parseInt(xh.trim()) + 1;
        String xh2=rmapper.selectywxhbyid(xh1).getXh();
        rmapper.updateghxhywxh(xh2,DateUtils.Getdnowdatexx());
        String  ghxh=String.valueOf(tempghxh+xh1);
        rmapper.saveghb(ghxh,ghzlbm,ghfsbm,fbbm,brid,czybm,czyks,
                ghks,brnl,zcrq,zcrq,ywckbm,jzys);
        rmapper.updatesfysghf(ghxh);
        return  ghxh;
    }
//当检验申请的时候数据库里面的时间和当前时间相差大于等于1天的时候执行
    private String jysqthan(Long tempjyxh,String ywckbm,String ryghxh,String zxks ,String sfjz,String lczd,String sjys,String sjrq,
                            String jehj,String yhhj,String sjhj,String sqsj,String sqys,String mzks,String sjysqz,String
                                    sjysqzsj,String kjlx,String mxfyxmbm,String je,String kfry,String kfrq){
        rmapper.updatejysqdywxh("000001",DateUtils.Getdnowdatexx());
        String  jysqdxh=String.valueOf(tempjyxh+1);
        jysqdBean bean=new jysqdBean();
        bean.setJysqh(jysqdxh.trim());bean.setYwckbm(ywckbm.trim());bean.setRyghxh(ryghxh.trim());bean.setZxks(zxks.trim());
        bean.setSfjz(sfjz.trim());bean.setLczd(lczd.trim());bean.setSjys(sjys.trim());bean.setSjrq(sjrq);bean.setJehj(jehj);bean.setYhhj(yhhj);
        bean.setSjhj(sjhj); bean.setSqsj(sqsj);bean.setSqys(sqys.trim());bean.setMzks(mzks.trim());bean.setSjysqz(sjysqz.trim());bean.setSjysqzsj(sjysqzsj);
        bean.setKjlx(kjlx);bean.setKfbz("1");bean.setKfry(kfry.trim());bean.setKfrq(kfrq);

        jysqdmxBean mxBean=new jysqdmxBean();
        mxBean.setJysqh(jysqdxh.trim());mxBean.setJysqmxxh("1");mxBean.setMxfyxmbm(mxfyxmbm);mxBean.setSl("1");
        mxBean.setDj(je);mxBean.setJe(je);mxBean.setYhbl("0");mxBean.setYhje("0");mxBean.setSfzhfy("0");
        mxBean.setZxks(zxks);mxBean.setKskfbz("0");mxBean.setDyxmxh("1");
        System.out.print("检验申请消息:"+JSON.toJSON(bean)+"<<---");
        mapper.InsertJysq(bean);
        mapper.InsertJysqmx(mxBean);


  return  jysqdxh;
    }
    /***当检验申请与数据库里面时间是同一天时候执行**/
   private String jysqLess(Long tempjyxh,String ywckbm,String ryghxh,String zxks ,String sfjz,String lczd,String sjys,String sjrq,
                           String jehj,String yhhj,String sjhj,String sqsj,String sqys,String mzks,String sjysqz,String
                                   sjysqzsj,String kjlx,String mxfyxmbm,String je,String xh,String kfry,String kfrq){
       //rmapper.updatejysqdywxh("000001",DateUtils.Getdnowdatexx());
       int xh1 = Integer.parseInt(xh.trim()) + 1;
       String xh2=rmapper.selectywxhbyid(xh1).getXh();
       rmapper.updatejysqdywxh(xh2,DateUtils.Getdnowdatexx());
       String  jysqdxh=String.valueOf(tempjyxh+xh1);
       jysqdBean bean=new jysqdBean();
       bean.setJysqh(jysqdxh.trim());bean.setYwckbm(ywckbm.trim());bean.setRyghxh(ryghxh.trim());bean.setZxks(zxks.trim());
       bean.setSfjz(sfjz.trim());bean.setLczd(lczd.trim());bean.setSjys(sjys.trim());bean.setSjrq(sjrq);bean.setJehj(jehj);bean.setYhhj(yhhj);
       bean.setSjhj(sjhj); bean.setSqsj(sqsj);bean.setSqys(sqys.trim());bean.setMzks(mzks.trim());bean.setSjysqz(sjysqz.trim());bean.setSjysqzsj(sjysqzsj);
       bean.setKjlx(kjlx.trim());bean.setKfbz("1");bean.setKfry(kfry.trim());bean.setKfrq(kfrq);
       jysqdmxBean mxBean=new jysqdmxBean();
       mxBean.setJysqh(jysqdxh);mxBean.setJysqmxxh("1");mxBean.setMxfyxmbm(mxfyxmbm);mxBean.setSl("1");
       mxBean.setDj(je);mxBean.setJe(je);mxBean.setYhbl("0");mxBean.setYhje("0");mxBean.setSfzhfy("0");
       mxBean.setZxks(zxks);mxBean.setKskfbz("0");mxBean.setDyxmxh("1");
       System.out.print("检验申请消息:"+JSON.toJSON(bean)+"<<---");
       mapper.InsertJysq(bean);
       mapper.InsertJysqmx(mxBean);

       return  jysqdxh;
   }
  //当结算记录中与数据库时间相差大于1天时候执行
   private String jsjlThan(Long tempjsjlid,String ghxh,String czybm,String ywckbm,String brid,String fyhj,String czyks,String ylkh){
       rmapper.updejsjlywxh("000001",DateUtils.Getdnowdatexx());
       String jsjlid=String.valueOf(tempjsjlid+1);
       JsjlBean jsjlBean=new JsjlBean(jsjlid,ghxh,"1",czybm,ywckbm,brid,fyhj,"0",
               fyhj,"0","0","0" ,"0","0",DateUtils.Getdnowdatexx(),czyks,
               "线上核酸检测结算","","0","0","0",ylkh,"0",
               "0","0","0");
       mapper.InsertGhbjsjl(jsjlBean);
       return  jsjlid;
   }

    /***
     * 当结算日期与数据库结算日期相差天数是1时候执行
     * @param tempjsjlid
     * @return
     */
   private String jsjlLess(Long tempjsjlid,String xh,String ghxh,String czybm,String ywckbm,String brid,String fyhj,String czyks,String ylkh){
       int xh1 = Integer.parseInt(xh.trim()) + 1;
       String xh2=rmapper.selectywxhbyid(xh1).getXh();
       rmapper.updejsjlywxh(xh2,DateUtils.Getdnowdatexx());
       String jsjlid=String.valueOf(tempjsjlid+xh1);
       JsjlBean jsjlBean=new JsjlBean(jsjlid,ghxh,"1",czybm,ywckbm,brid,fyhj,"0",
               fyhj,"0","0","0" ,"0","0",DateUtils.Getdnowdatexx(),czyks,
               "线上核酸检测结算","","0","0","0",ylkh,"0",
               "0","0","0");
       mapper.InsertGhbjsjl(jsjlBean);

       return  jsjlid;
   }

    /**填充预约记录**/
    private AutoOrderBean setAutoBean(String TypeName,String  TypeID, String DepName, String DeptID,String DoctID,
 String yyghrq,String ghxh,String yyghid,String ghf,String ispay,String PatientID,String CardNo,String DoctName,String czybm,String czyxm){
        AutoOrderBean a=new AutoOrderBean(yyghrq,TypeID,TypeName,DepName,DeptID,DoctID,
               DoctName,"",yyghid,"0",ghf,"0","0","",
                "","0","微信挂号",ispay,PatientID,CardNo,yyghid,ghxh,czybm,czyxm);
        return a;
    }
/***填充检验申请单用于插入数据表中**/
    private jysqdBean setJysqdBean(String jysqh,String ywckbm,String ryghxh, String zxks,String sfjz,String lczd,String sjys,String sjrq,String jehj,String yhhj,String sjhj,String sqsj,String sqys,String mzks,String sjysqz,String sjysqzsj,String kjlx){
        jysqdBean bean=new jysqdBean();
        bean.setJysqh(jysqh);
        bean.setYwckbm(ywckbm);
        bean.setZxks(zxks);
        bean.setSfjz(sfjz);
        bean.setLczd(lczd);
        bean.setSjys(sjys);
        bean.setSjrq(sjrq);
        bean.setJehj(jehj);
        bean.setYhhj(yhhj);
        bean.setSjhj(sjhj);
        bean.setSqsj(sqsj);
        bean.setSqys(sqys);
        bean.setMzks(mzks);
        bean.setSjysqz(sjysqz);
        bean.setSjysqzsj(sjysqzsj);
        bean.setKjlx(kjlx);
return  bean;
    }
/**填充检验申请明细对象用于插入检验申请明细表**/
    private jysqdmxBean setJysqdmxBean(String jysqh,String jysqmxxh,String mxfyxmbm,String sl,String dj,String je,String yhbl, String yhje,String sfzhfy, String zxks,String  kskfbz,String dyxmxh){
    jysqdmxBean bean=new jysqdmxBean();
    bean.setJysqh(jysqh);
    bean.setJysqmxxh(jysqmxxh);
    bean.setMxfyxmbm(mxfyxmbm);
    bean.setSl(sl);
    bean.setDj(dj);
    bean.setJe(je);
    bean.setYhbl(yhbl);
    bean.setYhje(yhje);
    bean.setSfzhfy(sfzhfy);
    bean.setZxks(zxks);
    bean.setKskfbz(kskfbz);
    bean.setDyxmxh(dyxmxh);
return bean;
}
   /***填充支付记录表****/
    private  PayDetailBean setPayBean(NaExamPatientInfo info,String jsxh,NaExamRequest r,String czybm,String czyxm){
        PayDetailBean pay=new PayDetailBean();
        pay.setBzms("微信核酸检测结算");
        pay.setPayTag(r.getPayTag());
        pay.setCodeTermidNo(r.getCodeTermidNo());
        pay.setPayTranDate(r.getPayTranDate());
        pay.setAddress(info.getAddress());
        pay.setAutoTranNo(r.getAutoTranNo());
        pay.setBankCardNo(r.getBankCardNo());
        pay.setBankPNo(r.getBankPNo());
        pay.setBankReferNo(r.getBankReferNo());
        pay.setBankTermid(r.getBankTermid());
        pay.setBirthday(info.getBirthday());
        pay.setCardType("01");
        pay.setCodeBuyerAccount(r.getCodeBuyerAccount());
        pay.setBankTranNo(r.getBankTranNo());
        pay.setJsxh(jsxh);
        pay.setCodeTradeOrderNo(r.getCodeTradeOrderNo());
        pay.setMobile(info.getMobile());
        pay.setName(info.getName());
        pay.setPayAmt(r.getPayAmt());
        pay.setIDCardNo(info.getIDCardNo());
        pay.setSex(info.getSex());
        pay.setUserId("wxhsjc");
        pay.setPayTranTime(r.getPayTranTime());
        if(info.getCardNo()!=null){
        pay.setCardNo(info.getCardNo());}
        else {
            pay.setCardNo(info.getIDCardNo());
        }
        pay.setPatientID(info.getPatientId());
        pay.setReqtype(r.getReqtype());
        pay.setCzybm(czybm);
        pay.setCzyxm(czyxm);
        return  pay;
    }

/***填充门诊表病人费用*/
    private  mzbBrfyBean setFyBean(String fbbm,String ywckbm,String xlbm,String mxfyxmbm,String czybm,String dlbm,String sfrq,String rybrid,String ryghxh,
   String brxm,String fysl,String ytsl,String fydj,String fyje,String mzys,String mzks,String hsks,String zxks,String yzlx,String yzhm,String yzxh,String bzsm,String sfjs,String mzzd,String sfzhfy,String sflx,String kskfbz,String kskfry,String kskfrq,String fphm,String jsid){
        mzbBrfyBean bean=new mzbBrfyBean();
        bean.setFbbm(fbbm);bean.setYwckbm(ywckbm);bean.setXlbm(xlbm);bean.setMxfyxmbm(mxfyxmbm);
        bean.setCzybm(czybm);bean.setDlbm(dlbm);bean.setSfrq(sfrq);bean.setRybrid(rybrid);bean.setRyghxh(ryghxh);
        bean.setBrxm(brxm);bean.setFysl(fysl); bean.setYtsl(ytsl);bean.setFydj(fydj);bean.setFyje(fyje);
        bean.setYhbl("0");bean.setYhje("0");bean.setMzys(mzys);bean.setMzks(mzks);bean.setHsks(hsks);
        bean.setZxks(zxks);bean.setYzlx(yzlx);bean.setYzhm(yzhm);bean.setYzxh(yzxh);bean.setBzsm(bzsm);
        bean.setSfjs(sfjs);bean.setMzzd(mzzd);bean.setSfzhfy(sfzhfy);bean.setSflx(sflx);bean.setKskfbz(kskfbz);
        bean.setKskfry(kskfry);bean.setKskfrq(kskfrq);bean.setJscs("1");bean.setFphm(fphm);bean.setRyjsjlid(jsid);
        return bean;
    }


}


